package com.soen6441.generics;
import java.util.Comparator;

class Correction {
    String word;
    Integer edditDistance;

    Correction(String word, int edditDistance) {
        this.word = word;
        this.edditDistance = edditDistance;
    }

    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Correction that = (Correction) o;

        if (edditDistance != that.edditDistance) return false;
        if (word != null ? !word.equals(that.word) : that.word != null) return false;

        return true;
    }

    public int hashCode() {
        int result = word != null ? word.hashCode() : 0;
        result = 31 * result + edditDistance;
        return result;
    }

    public String toString() {
        return word;
    }

    static class CorrectionComparator implements Comparator<Correction> {
        public int compare(Correction first, Correction second) {
            int edCompare = first.edditDistance.compareTo(second.edditDistance);
            if (0 != edCompare)
                return edCompare;
            return first.word.compareTo(second.word);
        }
    }
}
